import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import ElementPlus from "unplugin-element-plus/vite";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    // 按需定制主题配置
    ElementPlus({
      useSource: true,
      defaultLocale: "zh-tw",
    }),
  ],
  resolve: {
    alias: {
      "~/": `${path.resolve(__dirname, "src")}/`,
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "~/theme/style.scss" as *;`,
      },
    },
  },
  server: {
    proxy: {
      //代理配置
      "/heheda": {
        target: "https://m.wzj.com/", //目标域名
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            proxyReq.setHeader("Referer", "https://m.wzj.com/");
          });
        },
        rewrite: (path) => path.replace(/^\/heheda/, ""),
      },
      "/epet": {
        target: "https://mallcdn.api.epet.com", //目标域名
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            proxyReq.setHeader("Referer", "https://mallcdn.api.epet.com");
          });
        },
        rewrite: (path) => path.replace(/^\/epet/, ""),
      },
    },
  },
});
